package com.chenshu.test;

import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

/**
 * Created with IntelliJ IDEA
 * Description：快速入门
 * User：chenshu
 * Date：2024-03-26
 * Time：16:17
 */
public class Reflection01 {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        //1.读写文件
        Properties properties = new Properties();
        properties.load(new FileInputStream("src/static/re.properties"));
        String classPathName = properties.getProperty("classPath");
        String methodName = properties.getProperty("method");

        //2.使用反射机制
        //2.1 加载类
        Class clazz = Class.forName(classPathName);
        //2.2 通过clazz得到 com.chenshu.Obj 的对象实例
        Object o = clazz.newInstance();
        //2.3 通过clazz得到该类的方法并使用 Method 类来接收
        Method method = clazz.getMethod(methodName);
        //通过方法对象来调用方法
        method.invoke(o);

    }
}